<?php
	/*
	 * File: info_api.php
	 * Last modification: 20.07.2011
	 * Author(s): kivio.wanderley
	 * 
	 */
?>

<?php /** CENTER PHP CODE */
	
	# Set up error_handler() as the new default error handling function
	set_error_handler( 'error_handler' );
	
	/**
	 * Erro handler.
	 * @param $p_type
	 * @param $p_error
	 * @param $p_file
	 * @param $p_line
	 * @param $p_context
	 */
	function error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {
		$p_error = utf8_decode($p_error);
		
		switch ($p_type) {
    		case E_ERROR:
    		echo '<hr width=300px>';
	        echo "<b>ERROR</b> [$p_type] $p_error<br />\n";
	        echo "Error on line $p_line in file $p_file<br />\n";
	        echo "PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
	        echo "<br />\n";
	        echo "You can click 'Back' button on the browser to return.<br />\n";
	        echo '<hr width=300px>';
	        $arr = error_get_last();
	        echo $arr['message'];
//	        exit(1);
        	break;
        	
        	case E_CORE_ERROR:
    		echo '<hr width=300px>';
	        echo "<b>ERROR</b> [$p_type] $p_error<br />\n";
	        echo "Error on line $p_line in file $p_file<br />\n";
	        echo "PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
	        echo "<br />\n";
	        echo "You can click 'Back' button on the browser to return.<br />\n";
	        echo '<hr width=300px>';
	        $arr = error_get_last();
	        echo $arr['message'];
//	        exit(1);
        	break;
        	
		}

	}

	function set_info_msg($p_info, $p_info_class = 0, $p_redirect_url = null) {
//		session_start();
		
		# Information string
		$_SESSION['info'] = $p_info;
		# Set type of info for color
		if($p_info_class == 0) $t_class = "info_err";
		elseif($p_info_class == 1) $t_class = "info_ok";
		elseif($p_info_class == 2) $t_class = "info_warn";
		$_SESSION['info_class'] = $t_class;
		
		if( $p_redirect_url == null )
			print_header_redirect($_SERVER['HTTP_REFERER']);
		else
			print_header_redirect($p_redirect_url);
	}
	
?>